package com.jule.goldfast.game.service;

import com.jule.core.jedis.StoredObjManager;
import com.jule.goldfast.base.enums.RedisConst;
import com.jule.goldfast.base.model.RoomTableRelationModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xujian 2017-12-18
 * 通过修改redis 状态维护房间服务器缓存，包括 入桌/退桌 坐下/站起
 */
public class RoomStateService {
    private final static Logger logger = LoggerFactory.getLogger(RoomStateService.class);
    private final static String ROOM_STAT = "ROOM_STAT_";

    private static class SingletonHolder {
        protected static final RoomStateService instance = new RoomStateService();
    }

    public static final RoomStateService getInstance() {
        return RoomStateService.SingletonHolder.instance;
    }



    /**
     * @param roomId
     * @param tableId
     * @return RoomTableRelationModel
     */
    public RoomTableRelationModel getExistTable(String gameId, String roomId, String tableId) {
        RoomTableRelationModel ret = StoredObjManager.getStoredObjInMap(RoomTableRelationModel.class,
                RedisConst.TABLE_INSTANCE.getProfix() + gameId + roomId,
                RedisConst.TABLE_INSTANCE.getField() + tableId);

        logger.info("getExistTable() gameId->"+gameId+" roomId->"+roomId+",tableId ->"+tableId+(ret!=null?" "+ret.toString():" ret is null"));
        if (ret != null) {
            return ret;
        }
        return null;
    }

}
